/*
	Copyright (C) 2013 Pontificia Universidad Catolica del Peru
	contact: http://avatar.inf.pucp.edu.pe/realidad-aumentada/
	address contact: Av. Universitaria 1801, San Miguel, Lima-Peru.
	
	This file is part of UbicAR PUCP.

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with This program.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Authors: Alvaro Roger Agüero Sánchez, Rodolfo Javier Galvez Meza
	Pontificia Universidad Catolica del Peru
	Departamento de Ingeniería
*/

package org.grupoavatar.guiaubicua.auxiliares;

import java.util.ArrayList;

import org.grupoavatar.guiaubicua.VInicial;

import android.content.SharedPreferences;

public class Usuario {
	public static int id_usuario=0; //cambiar por private
	public static String correo_actual = "";
	public static ArrayList<String> cuentas;
	public static boolean esValido = false;
	
	public static Item[] getCuentas() {
		ArrayList<Item> tempCuentas = new ArrayList<Item>();
		for (String cuenta : cuentas) {
			tempCuentas.add(new Item(cuenta, null, -1));
		}
		Item[] items = tempCuentas.toArray(new Item[tempCuentas.size()]);
		
		return items;
	}
	
	public static void asignarUsuario(int id) {
		esValido = false;
		id_usuario = id;
		try {
			if (id > 0 && !correo_actual.equals(""))
				esValido = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		try {
			SharedPreferences settings = VInicial.getContext().getSharedPreferences(VInicial.PREFS_NAME, 0);
			SharedPreferences.Editor editor = settings.edit();		
			editor.putInt("usuario", id_usuario);
			editor.putString("correo", correo_actual);
			editor.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void desasociarCuenta() {
		correo_actual = "";
		asignarUsuario(0);
	}
}
